﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Threading;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace CityLife
{
    public partial class Clock : UserControl
    {
        public double Tempo = 1;
        DispatcherTimer dt;
        public DateTime ClockTime = DateTime.Now;

        public Clock()
        {
            
        }

        public void Begin()
        {
            dt = new DispatcherTimer();
            InitializeComponent();
            //Define the event that will occur at timer tick
            dt.Tick += new EventHandler(CreateClock);
            //Set the timer interval
            dt.Interval = TimeSpan.FromMilliseconds(1000 / Tempo);
            //strat the timer
            dt.Start();

        }

        void CreateClock(object sender, EventArgs e)
        {
         ClockTime=   ClockTime.AddSeconds(60);

         MainPage.Heart.City.CityStatus.CityDate = ClockTime;
         GameDate.Text = ClockTime.ToString("dd.M.yyyy");

            TextBlockDigital.Text = ClockTime.ToLongTimeString();
            RotateTransform rotateTransform = new RotateTransform();
            //Set the angle of Second and SecondShadow
            //One tick=6 degrees
            /*rotateTransform.Angle = ClockTime.Second * 6;
            Second.RenderTransform = rotateTransform;
            SecondShadow.RenderTransform = rotateTransform;
             * */
            //Set the angle of Minute and SecondShadow
            //rotateTransform = new RotateTransform();
            //rotateTransform.Angle = ClockTime.Minute * 6;
            //Minute.RenderTransform = rotateTransform;
            //MinuteShadow.RenderTransform = rotateTransform;

            int hr = ClockTime.Hour;
            if (hr >= 12)
                hr = hr - 12;
            //Set the angle of Hour and HourShadow
            rotateTransform = new RotateTransform();
            rotateTransform.Angle = (hr * 30) + ClockTime.Minute / 2;
            Hour.RenderTransform = rotateTransform;
            HourShadow.RenderTransform = rotateTransform;
        }

        
    }
}
